﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Takkou.Language
{
    // Represents a 'repeat X times' statement.
    // This statement executes the block a fixed number of times.
    public class Repeat : Statement
    {
        public int Count { get; private set; }
        public int NumTimes { get; private set; }
        public Block Block { get; private set; }

        // constructor
        public Repeat(int num, Block block)
        {
            NumTimes = num;
            Block = block;
            Count = 0;
        }

        public override void start()
        {
            Count = 0;
            Block.start();
        }
            
        public override bool execute()
        {
            // check if the block execution has finished
            if (Block.execute() == false)
            {
                Count++;
                Block.start();
            }
            return Count < NumTimes;  // return true if Count has not yet reached NumTimes
        }
    }
}
